// 用户状态
import { userAccountLogin } from '@/api/user'
export default {
  namespaced: true,
  state: () => ({
    profile: {
      id: '',
      avatar: '',
      nickname: '',
      account: '',
      mobile: '',
      token: ''
    }
  }),

  mutations: {
    // 登录
    setProfile (state, payload) {
      state.profile = payload
    },
    // 退出登录
    delProfile (state) {
      state.profile = {}
    }
  },

  actions: {
    // 登录
    async getProfileAction ({ commit }, payload) {
      const res = await userAccountLogin(payload)
      // console.log(res)
      commit('setProfile', res.result)
    },

    // 退出登录 删除用户信息及购物车信息
    delProfileAction ({ commit }) {
      commit('delProfile')
    }
  }
}
